package com.zy.cat.controller.v1;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.zy.cat.common.annotation.CheckDevPermission;
import com.zy.cat.common.annotation.CheckingMD5;
import com.zy.cat.common.config.Configs;
import com.zy.cat.common.utils.AesEncryptUtils;
import com.zy.cat.common.utils.CalculateUtil;
import com.zy.cat.common.utils.TJKUtils;
import com.zy.cat.entity.app.CatAppUseVideo;
import com.zy.cat.entity.app.resp.CatAppConfigInfoResp;
import com.zy.cat.entity.app.resp.CatAppConfigInfoResp.BottomButton;
import com.zy.cat.entity.app.resp.CatAppMessageResp;
import com.zy.cat.entity.app.resp.CatAppNoticeResp;
import com.zy.cat.entity.app.CatAppUseVideo;
import com.zy.cat.entity.app.resp.CatAppVersionInfoResp;
import com.zy.cat.entity.app.resp.NewItemResp;
import com.zy.cat.entity.resp.RSPE;
import com.zy.cat.service.CatUtilsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(value = "9catDevHelps", tags = { "9趣猫工具开放API" }, description = "9趣猫工具开放接口")
@RestController
@RequestMapping("/v1/helps")
@Slf4j
public class HelpsController {

	@Autowired
	Configs configs;

	@Autowired
	CatUtilsService catUtilsService;
	
	@Autowired
	@Qualifier("redis0")
	RedisTemplate<String, Object> redis0;
	
	@Autowired
	@Qualifier("redis15")
	RedisTemplate<String, Object> redis15;
	
	@Autowired
	@Qualifier("redis6")
	RedisTemplate<String, Object> redis6;

	@PostMapping("/sms")
	@ApiOperation(value = "9趣猫发送短信", position = 1, consumes = "application/x-www-form-urlensignd", notes = "", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "APP友盟渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "phone", value = "手机号码", example = "13854107520", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "sign", value = "短信签名", example = "九趣猫", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "stype", value = "短信类型（1.绑定手机）", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_phone_stype_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_uuid_phone_stype", MD5 = "token")
	@CheckDevPermission
	public Object sendMsg(Integer rtype, Integer stype, String brand, String model, String vscode, String cid,
			String imei, String imsi, String phone, String sign,String pid,String utoken, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if (stype == null || stype != 1) {
			return new RSPE<Object>(-3, "短信类型参数错误！");
		}
		Callable<RSPE<String>> result = new Callable<RSPE<String>>() {
			@Override
			public RSPE<String> call() throws Exception {
				if (catUtilsService.sendMsg(stype, phone, sign)) {
					return new RSPE<String>(1, "成功！");
				}
				return new RSPE<String>(0, "失败！");
			}
		};
		return result;
	}

	@PostMapping("/upload/img")
	@ApiOperation(value = "上传图片", position = 2)
	@ApiImplicitParams({})
	public RSPE<Object> uploadImg(@RequestParam("file") MultipartFile file) {
		if (file == null || file.getOriginalFilename() == null || !file.getOriginalFilename().contains(".")) {
			return new RSPE<Object>(0, "上传失败");
		}
		//判断是否超出10M
		if (!CalculateUtil.checkFileSize( file.getSize(),10,"M")) {
			return new RSPE<Object>(-1, "文件过大");
		}
		String fileMD5 = null;
		try {
			fileMD5 = DigestUtils.md5DigestAsHex(file.getBytes());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		String contentType = file.getContentType(); // 图片文件类型
		String fileName = file.getOriginalFilename(); // 图片名字
		String suffix = fileName.substring(fileName.lastIndexOf("."));
		String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(20);
		String tempFileName = uuid + suffix;

		if (StringUtils.isNotBlank(fileMD5)) {
			tempFileName = fileMD5 + suffix;
		}

		String des = configs.getDesPath() + "imgs/" + tempFileName;
		String urlPath = configs.getCdnImgUrl() + "/imgs/" + tempFileName;
		if (contentType.startsWith("image")) {
			urlPath = configs.getCdnImgUrl() + "/imgs/" + tempFileName;
		}

		log.info("FileMD5--->{}", fileMD5);
		log.info("desFiles--->{}", des);
		log.info("urlPath--->{}", urlPath);
		log.info("contentType--->{}", contentType);
		File desFile = new File(des);

		log.info("-urlPathExists--->{}", desFile.exists());
		if (desFile.exists()) {
			return new RSPE<Object>(1, "success", urlPath);
		}

		if (!desFile.getParentFile().exists()) {
			desFile.getParentFile().mkdirs();
		}
		try {
			file.transferTo(desFile);
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new RSPE<Object>(1, "success", urlPath);
	}

	@PostMapping("/upload/files")
	@ApiOperation(value = "上传文件", position = 3)
	@ApiImplicitParams({})
	public RSPE<Object> uploadFiles(@RequestParam("file") MultipartFile file, HttpServletRequest req,
			HttpServletResponse resp) {
		if (file == null || file.getOriginalFilename() == null || !file.getOriginalFilename().contains(".")) {
			return new RSPE<Object>(0, "上传失败");
		}

		String fileMD5 = null;
		try {
			fileMD5 = DigestUtils.md5DigestAsHex(file.getBytes());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		String contentType = file.getContentType(); // 图片文件类型
		String fileName = file.getOriginalFilename(); // 图片名字
		String suffix = fileName.substring(fileName.lastIndexOf("."));
		String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(20);
		String tempFileName = uuid + suffix;
		if (StringUtils.isNotBlank(fileMD5)) {
			tempFileName = fileMD5 + suffix;
		}

		String des = configs.getDesPath() + "files/" + tempFileName;
		String urlPath = configs.getCdnUrl() + "/files/" + tempFileName;
		if (contentType.endsWith("mp4")) {
			urlPath = configs.getCdnUrl() + "/files/" + tempFileName;
		}

		log.info("desFiles--->{}", des);
		log.info("urlPath--->{}", urlPath);
		log.info("contentType--->{}", contentType);
		File desFile = new File(des);

		if (desFile.exists()) {
			return new RSPE<Object>(1, "success", urlPath);
		}
		log.info("-urlPathExists--->{}", desFile.exists());

		if (!desFile.getParentFile().exists()) {
			desFile.getParentFile().mkdirs();
		}
		try {
			file.transferTo(desFile);
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return new RSPE<Object>(1, "success", urlPath);
	}

	@PostMapping("/time")
	@ApiOperation(value = "获取目前网络时间", position = 4, consumes = "application/x-www-form-urlensignd", notes = "", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "APP友盟渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_brand_model_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_uuid_brand_model", MD5 = "token")
	public Object getTime(Integer rtype, String brand, String model, String vscode, String cid, String imei,
			String imsi, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("t1", TJKUtils.DateTime());
		result.put("t2", System.currentTimeMillis());
		return new RSPE<Object>(result);
	}
	
	@PostMapping("/wx")
	@ApiOperation(value = "9趣猫获取微信配置信息",consumes = "application/x-www-form-urlencoded", position = 5, notes = "9趣猫获取微信配置信息", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "APP友盟渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_brand_uuid_vscode_cid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form")})
	@CheckingMD5(checkingStr = "rtype_brand_uuid_vscode_cid", MD5 = "token")
	public Object getWelfareInfo(Integer rtype, String brand, String model, String vscode, String cid, String imei,
			String imsi, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<String>(-2, "应用平台参数错误！");
		}
		//判断Redis中是否已经存在此key
		Map<String, String> resultMap=new HashMap<>();
		//获取微信授权信息
		resultMap.put("w1", configs.getWeappid());
		resultMap.put("w2", configs.getWesecret());
		String ciphertext =AesEncryptUtils.encryptBySalt(JSON.toJSONString(resultMap));
		return new RSPE<String>(ciphertext);
	}
//	@PostMapping("/test")
//	@ApiOperation(value = "测试",consumes = "application/x-www-form-urlencoded", position = 12, notes = "测试", response = RSPE.class)
//	public Object test(String pid) {
//		return new RSPE<String>(catUtilsService.test(pid));
//	}
	
	@PostMapping("/tblink")
	@ApiOperation(value = "9趣猫获取淘宝推广链接",consumes = "application/x-www-form-urlencoded", position = 6, notes = "9趣猫获取淘宝推广链接", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_rtype_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form")})
	@CheckingMD5(checkingStr = "rtype_uuid_rtype", MD5 = "token")
	public Object getTbLink(Integer rtype, String uuid,String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<String>(-2, "应用平台参数错误！");
		}
		return new RSPE<String>(configs.getTbLink());
	}
	
	@PostMapping("/login/mode")
	@ApiOperation(value = "9趣猫获取登录方式",consumes = "application/x-www-form-urlencoded", position = 7, notes = "9趣猫获取登录方式(是否支持账号密码登录)", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "version", value = "版本号", example = "101", dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "cid", value = "渠道号", example = "official-001", required = false, dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_version_uuid_version_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form")})
	@CheckingMD5(checkingStr = "rtype_version_uuid_version", MD5 = "token")
	public Object getLoginMode(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId,String version,@RequestParam(required = false,defaultValue = "official-001") String cid, String uuid,String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<String>(-2, "应用平台参数错误！");
		}
		if (StringUtils.isEmpty(version)) {
			return new RSPE<String>(-3, "版本号不能为空");
		}
		Map<String, Integer> map=new HashMap<>();
		//登录方式控制
		String key="CAT_DEV_LOGIN_MODE_KEY";
		String hashKey=(rtype==0?"Android":"IOS")+"_"+cid+"_"+appId;
		if(redis15.hasKey(key) &&  StringUtils.equals((String)redis15.opsForHash().get(key, hashKey), version)) {
			map.put("show", 1);
		}else {
			map.put("show", 0);
		}
		return new RSPE<Map<String, Integer>>(map);
	}
	
	@PostMapping("/app/version/check")
	@ApiOperation(value = "9趣猫检查app版本更新", position = 8, consumes = "application/x-www-form-urlensignd", notes = "9趣猫检查app版本更新", response = CatAppVersionInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道号", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_brand_imei_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_uuid_brand_imei", MD5 = "token")
	public Object checkAppVersion(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId, String brand, String model, String vscode, String cid,
			String imei, String imsi, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		Callable<RSPE<CatAppVersionInfoResp>> result = new Callable<RSPE<CatAppVersionInfoResp>>() {
			@Override
			public RSPE<CatAppVersionInfoResp> call() throws Exception {
				CatAppVersionInfoResp resp=catUtilsService.checkAppVersion(rtype,appId, brand, model,vscode,cid);
				if (resp!=null) {
					return new RSPE<CatAppVersionInfoResp>(resp);
				}
				return new RSPE<CatAppVersionInfoResp>(1,"暂无版本更新！");
			}
		};
		return result;
	}
	
	@PostMapping("/message/info")
	@ApiOperation(position = 9, value = "用户获取推送的消息", notes = "个人中心获取推送消息", response = CatAppNoticeResp.class, responseContainer = "Map", consumes = "application/x-www-form-urlencoded")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_rtype_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	
	@CheckingMD5(checkingStr = "pid_uuid_rtype_utoken", MD5 = "token")
	@CheckDevPermission
	public Object setMessageInfo(Integer rtype,  String pid,String utoken, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		Callable<RSPE<CatAppNoticeResp>> result=new Callable<RSPE<CatAppNoticeResp>>() {
			@Override
			public RSPE<CatAppNoticeResp> call() throws Exception {
				CatAppNoticeResp atAppNotice=catUtilsService.getMessageInfo(rtype, pid);
				if (atAppNotice==null) {
					return new RSPE<CatAppNoticeResp>(0,"暂无消息");
				}
				return new RSPE<CatAppNoticeResp>(atAppNotice);
			}
		};
		return result;
	}
	
	@PostMapping("/message/info2")
	@ApiOperation(position = 9, value = "用户获取推送的消息与推送的商品", notes = "个人中心获取推送消息", response = CatAppNoticeResp.class, responseContainer = "Map", consumes = "application/x-www-form-urlencoded")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "版本号", example = "101", dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "cid", value = "渠道号", example = "official-001", required = false, dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(vscode_uuid_rtype_cid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	
	@CheckingMD5(checkingStr = "vscode_uuid_rtype_cid", MD5 = "token")
	public Object setMessageInfo2(Integer rtype,  String pid,Integer appId, String uuid, String token,String cid,String vscode) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		Callable<RSPE<CatAppMessageResp>> result=new Callable<RSPE<CatAppMessageResp>>() {
			@Override
			public RSPE<CatAppMessageResp> call() throws Exception {
				CatAppMessageResp atAppNotice=catUtilsService.getMessageInfo2(rtype, pid);
				if (atAppNotice==null) {
					return new RSPE<CatAppMessageResp>(0,"暂无消息");
				}
				return new RSPE<CatAppMessageResp>(atAppNotice);
			}
		};
		return result;
	}

	
	@PostMapping("/config")
	@ApiOperation(value = "获取启动配置信息",consumes = "application/x-www-form-urlencoded", position = 10, notes = "配置信息包括启动闪屏页图片、广告开关、版本更新、登录方式等", response = CatAppConfigInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "vscode", value = "版本号", example = "101", dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "cid", value = "渠道号", example = "official-001", required = false, dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_vscode_uuid_cid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form")})
	@CheckingMD5(checkingStr = "rtype_vscode_uuid_cid", MD5 = "token")
	public Object getAppConfigInfo(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId,String vscode,@RequestParam(required = false,defaultValue = "official-001") String cid, String uuid,String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<CatAppConfigInfoResp>(-2, "应用平台参数错误！");
		}
		if (StringUtils.isEmpty(vscode)) {
			return new RSPE<CatAppConfigInfoResp>(-3, "版本号不能为空");
		}
		Callable<RSPE<CatAppConfigInfoResp>> result=new Callable<RSPE<CatAppConfigInfoResp>>() {
			@Override
			public RSPE<CatAppConfigInfoResp> call() throws Exception {
				CatAppConfigInfoResp atAppNotice=catUtilsService.getAppConfigInfo(rtype,appId,vscode,cid);
				if (atAppNotice==null) {
					return new RSPE<CatAppConfigInfoResp>(0,"获取失败");
				}
				return new RSPE<CatAppConfigInfoResp>(atAppNotice);
			}
		};
		return result;
	}
	
	@PostMapping("/new/data")
	@ApiOperation(value = "获取极速数据的新闻数据",consumes = "application/x-www-form-urlencoded", position = 11, notes = "获取极速数据的新闻数据", response = NewItemResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
 			@ApiImplicitParam(name = "vscode", value = "版本号", example = "101", dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "channel", value = "频道", example = "头条", dataType = "String", paramType = "form",required = false),
 			@ApiImplicitParam(name = "pageNum", value = "分页", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pageSize", value = "分页大小（10~100）", example = "10", required = true, dataType = "String", paramType = "form"),
 			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_vscode_uuid_pageNum_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form")})
	@CheckingMD5(checkingStr = "rtype_vscode_uuid_pageNum", MD5 = "token")
	public Object getNewData(Integer rtype,String vscode,@RequestParam(defaultValue = "女性") String channel,Integer pageNum,Integer pageSize, String uuid,String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<List<NewItemResp>>(-2, "应用平台参数错误！");
		}
		if (StringUtils.isEmpty(vscode)) {
			return new RSPE<List<NewItemResp>>(-3, "版本号不能为空");
		}
		Callable<RSPE<List<NewItemResp>>> result=new Callable<RSPE<List<NewItemResp>>>() {
			@Override
			public RSPE<List<NewItemResp>> call() throws Exception {
				List<NewItemResp> data=catUtilsService.getNewData(rtype,channel,vscode,pageNum,pageSize);
				if (data==null) {
					return new RSPE<List<NewItemResp>>(0,"获取失败");
				}
				return new RSPE<List<NewItemResp>>(data);
			}
		};
		return result;
	}
	
	@PostMapping("/video")
	@ApiOperation(value = "获取新手教程视频",consumes = "application/x-www-form-urlencoded", position = 10, notes = "新手教程视频(引导用户使用)", response = CatAppUseVideo.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "id", value = "视频id", example = "1", required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_id_uuid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form")})
	@CheckingMD5(checkingStr = "rtype_id_uuid", MD5 = "token")
	public Object getUseVideo(Integer rtype,Integer id,String uuid,String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<CatAppUseVideo>(-2, "应用平台参数错误！");
		}
		Callable<RSPE<List<CatAppUseVideo>>> result=new Callable<RSPE<List<CatAppUseVideo>>>() {
			@Override
			public RSPE<List<CatAppUseVideo>> call() throws Exception {
				List<CatAppUseVideo> useVideo=catUtilsService.getUseVideo(rtype,id);
				if (useVideo==null) {
					return new RSPE<List<CatAppUseVideo>>(0,"获取失败");
				}
				return new RSPE<List<CatAppUseVideo>>(useVideo);
			}
		};
		return result;
	}
	
}
